package com.xinggq.pay.service.exception;

import com.xinggq.common.CommonResult;
import com.xinggq.common.exception.BaseGlobalExceptionHandler;
import com.xinggq.pay.api.exception.PayException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import jakarta.servlet.http.HttpServletRequest;

/**
 * 支付中心全局异常处理器
 * 继承基础异常处理器，扩展支付相关的异常处理
 * 
 * @author xinggq
 * @since 2024-01-01
 */
@Slf4j
@RestControllerAdvice
@Order(10) // 设置较高优先级，优先处理支付相关异常
public class GlobalExceptionHandler extends BaseGlobalExceptionHandler {

    /**
     * 处理支付异常
     */
    @ExceptionHandler(PayException.class)
    public CommonResult<Object> handlePayException(PayException e, HttpServletRequest request) {
        log.error("支付异常 - 请求路径: {}, 错误码: {}, 错误信息: {}", 
                request.getRequestURI(), e.getCode(), e.getMessage(), e);
        
        return CommonResult.result(e.getCode(), e.getMessage()).setData(e.getData());
    }
}